#!/usr/bin/env python
#coding=utf-8

import os
import json
import yaml
from core.logger import logger

class K8sUtils(object):

    def __init__(self):
        pass


    @classmethod
    def cpu_unit_to_G(cls, cpu: str):
        """
        cpu单位统一转为：核
        """
        if cpu.endswith("m"):
            result = int(cpu.replace("m", "")) / 1000
        else:
            result = int(cpu)

        return result


    @classmethod
    def mem_unit_to_G(cls, mem: str):
        """
        内存单位统一转为： G
        """
        if mem.endswith("Ki"):
            result = int(mem.replace("Ki", "")) / 1024 / 1024
        elif mem.endswith("K"):
            result = int(mem.replace("K", "")) / 1024 / 1024
        elif mem.endswith("Mi"):
            result = int(mem.replace("Mi", "")) / 1024
        elif mem.endswith("M"):
            result = int(mem.replace("M", "")) / 1024
        elif mem.endswith("Gi"):
            result = int(mem.replace("Gi", ""))
        elif mem.endswith("G"):
            result = int(mem.replace("G", ""))
        else:
            result = int(mem)

        return result

